<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>异步串行任务</title>
</head>
<body>
    
</body>

<script>

    function series(tasks) {
        return tasks.reduce((promiseChain, curTask) => {
            return promiseChain.then(res => {
                return curTask().then(curRes => {
                    return res.concat(curRes);
                })
            })
        }, Promise.resolve([]));
    }

    // function series(tasks) {
    //     return tasks.reduce((promiseChain, curTask) => {
    //         return promiseChain.then(res => {
    //             return curTask().then(curRes => {
    //                 return res.concat(curRes);
    //             })
    //         })
    //     }, Promise.resolve([]));
    // }

    const myPromise = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve("World");
            }, 1000);
        });

        const wrappedPromise = Promise.resolve(myPromise);
        console.log(wrappedPromise);

        wrappedPromise.then((value) => {
            console.log(value); // 输出: "World"
        });

</script>

</html>